var pageii = null;

var grid = null;
$(function() {

	grid = lyGrid({
		pagId : 'paging',
		l_column : [ {
			colkey : "id",
			name : "id"
		},{
			colkey : "equipmentCategoryId",
			name : "设备种类"
		},{
			colkey : "equipmentName",
			name : "设备名称"
		},{
			colkey : "equipmentNo",
			name : "设备编号"
		},{
			colkey : "leaveModel",
			name : "出厂型号"
		},{
			colkey : "managementNo",
			name : "管理编号"
		},{
			colkey : "produceFactory",
			name : "制造厂商"
		},{
			colkey : "telephone",
			name : "联系电话"
		},{
			colkey : "address",
			name : "厂家地址"
		}
		,{
			colkey : "installDate",
			name : "安装日期",
			renderData : function(rowindex,data, rowdata, column) {
				return new Date(data).format("yyyy-MM-dd hh:mm:ss");
		}
		},{
			colkey : "position",
			name : "安装地点"
		},{
			colkey : "regularMaintainDate",
			name : "定期保养日期",
			renderData : function(rowindex,data, rowdata, column) {
				return new Date(data).format("yyyy-MM-dd hh:mm:ss");
		}
		},{
			colkey : "nextMaintainDate",
			name : "下次保养日期",
			renderData : function(rowindex,data, rowdata, column) {
				return new Date(data).format("yyyy-MM-dd hh:mm:ss");
		}
		},{
			colkey : "beginDate",
			name : "开始使用日期",
			renderData : function(rowindex,data, rowdata, column) {
				return new Date(data).format("yyyy-MM-dd hh:mm:ss");
		}
		},{
			colkey : "normalTime",
			name : "正常使用时间",
			renderData : function(rowindex,data, rowdata, column) {
				return new Date(data).format("yyyy-MM-dd hh:mm:ss");
		}
		},{
			colkey : "equipmentStatus",
			name : "设备状态"
		},{
			colkey : "remark",
			name : "备注"
		},{
			colkey : "equipmentSparepartId",
			name : "设备零配件表"
		},{
			colkey : "price",
			name : "价格"
		},{
			colkey : "fillPeopleId",
			name : "填报人"
		},{
			colkey : "status",
			name : "状态"
		},{
			colkey : "operation",
			name : "操作"
		},],
		jsonUrl : rootPath + '/equip/equip_fileByPage.shtml',
		dymCol:true,
		checkbox : true,
		serNumber : false
	});
	$("#scrap").click("click", function() {
		
		scrapAccount();
	});
	$("#editFun").click("click", function() {
		
		editAccount();
	});
	$("#delFun").click("click", function() {
		delAccount();
	});
	$("#mainten").click("click", function() {
	
		maintenAccount();
	});
	$("#search").click("click", function() {// 绑定查询按扭
		
		var searchParams = $("#searchForm").serializeJson();
		grid.setOptions({
			data : searchParams
		});
	});
	
});
function editAccount() {
	var cbox = grid.getSelectedCheckbox();
	if (cbox.length > 1 || cbox == "") {
		layer.msg("只能选中一个");
		return;
	}
	pageii = layer.open({
		title : "编辑订单",
		type : 2,
		area : [ "800px", "100%" ],
		content : rootPath + '/equip/file_edit.shtml?id=' + cbox
	});
}
function delAccount() {
	var cbox = grid.getSelectedCheckbox();
	if (cbox == "") {
		layer.msg("请选择删除项！！");
		return;
	}
	layer.confirm('是否删除？', function(index) {
		var url = rootPath + '/equip/file_deleteEntity.shtml';
		var s = CommnUtil.ajax(url, {
			ids : cbox.join(",")
		}, "json");
		if (s == "success") {
			layer.msg('删除成功');
			grid.loadData();
		} else {
			layer.msg('删除失败');
		}
	});
}

function maintenAccount() {
	var cbox = grid.getSelectedCheckbox();
	if (cbox == "") {
		layer.msg("请选择维修项！！");
		return;
	}
	layer.confirm('是否维修？', function(index) {
		var url = rootPath + '/equip/file_maintenEntity.shtml';
		var s = CommnUtil.ajax(url, {
			ids : cbox.join(",")
		}, "json");
		if (s == "success") {
			layer.msg('添加维修成功');
			grid.loadData();
		} else {
			layer.msg('添加维修失败');
		}
	});
}
function scrapAccount() {
	var cbox = grid.getSelectedCheckbox();
	if (cbox == "") {
		layer.msg("请选择报废项！！");
		return;
	}
	layer.confirm('是否报废？', function(index) {
		var url = rootPath + '/equip/equip_filescrapEntity.shtml';
		var s = CommnUtil.ajax(url, {
			ids : cbox.join(",")
		}, "json");
		if (s == "success") {
			layer.msg('报废成功');
			grid.loadData();
		} else {
			layer.msg('报废失败');
		}
	});
}
